package store

import (
	"github.com/pkg/errors"
	"github.com/stackrox/hashstructure"
	"github.com/stackrox/rox/generated/storage"
	"github.com/stackrox/rox/pkg/set"
	"github.com/stackrox/rox/sensor/common/service"
)

// Dependencies are properties that belong to a storage.Deployment object, but don't come directly from the
// k8s deployment spec. They need to be enhanced from other resources, like RBACs and Services.
type Dependencies struct {
	PermissionLevel storage.PermissionLevel
	Exposures       []map[service.PortRef][]*storage.PortConfig_ExposureInfo
	LocalImages     set.StringSet
}

// GetHash generates a hash value for the Dependencies struct.
func (d *Dependencies) GetHash() (uint64, error) {
	h, err := hashstructure.Hash(d, &hashstructure.HashOptions{
		ZeroNil:         true,
		IgnoreZeroValue: true,
		SlicesAsSets:    true,
	})
	if err != nil {
		return 0, errors.Wrap(err, "hashing dependencies")
	}
	return h, nil
}
